<template>
	<view class="content">
		<view class="row b-b">
			<text class="tit">联系人</text>
			<input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名" placeholder-class="placeholder" />
		</view>
		<view class="row b-b">
			<text class="tit">手机号</text>
			<input class="input" type="number" v-model="addressData.phone" placeholder="收货人手机号码" placeholder-class="placeholder" />
		</view>
		<view class="row b-b">
			<text class="tit">地址</text>
			<text @click="chooseLocation" class="input">
				{{addressData.area}}
			</text>
			<text class="yticon icon-shouhuodizhi"></text>
		</view>
		<view class="row b-b"> 
			<text class="tit">详细地址</text>
			<textarea style="height:90rpx" v-model="addressData.detailed_address" type="text" placeholder="请输入详细地址" />
		</view>
		
		<view class="row default-row">
			<text class="tit">设为默认</text>
			<switch :checked="addressData.is_default" color="#fa436a" @change="switchChange" />
		</view>
		<button class="add-btn" @click="confirm">提交</button>
		<selectAddress ref='selectAddress' @selectAddress="successSelectAddress"></selectAddress>
	</view>
</template>

<script>
	import selectAddress from '@/components/yixuan-selectAddress/yixuan-selectAddress.vue'
	export default {
		components:{
			selectAddress
		},
		data() {
			return {
				addressData: {
					name: '',
					phone: '',
					detailed_address: '',
					area: '点击选择',
					is_default: false
				}
			}
		},
		onLoad(option){
			
			let title = '新增收货地址';
			if(option.type==='edit'){
				title = '编辑收货地址'
				
				this.addressData = JSON.parse(option.data)
			}
			this.manageType = option.type;
			uni.setNavigationBarTitle({
				title
			})
		},
		methods: {
			successSelectAddress(address){
				
				this.addressData.area=address
				
				
			},
			chooseLocation(){
				this.$refs.selectAddress.show()
			},
			switchChange(e){
				
				this.addressData.is_default = e.detail.value;
			},
			
			
			
			//提交
			confirm(){
				let data = this.addressData;
				// if(!data.name){
					
				// 	return;
				// }
				
				// if(!data.address){
					
				// 	return;
				// }
				// if(!data.area){
					
				// 	return;
				// }
				
				let that=this
				that.apipost('/api/user/submit_address',data,true).then(res => {
					if(res.Code==10200){
						
						uni.showToast({
						    title: res.Message,
						    duration:4000,
							icon:'none'
						});
						uni.navigateBack()
					}
					
				}).catch(err=>{
					console.log(err)
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: $page-color-base;
		padding-top: 16rpx;
	}

	.row{
		display: flex;
		align-items: center;
		position: relative;
		padding:0 30rpx;
		min-height: 110rpx;
		background: #fff;
		
		.tit{
			flex-shrink: 0;
			width: 120rpx;
			font-size: 30rpx;
			color: $font-color-dark;
		}
		.input{
			flex: 1;
			font-size: 30rpx;
			color: $font-color-dark;
		}
		.icon-shouhuodizhi{
			font-size: 36rpx;
			color: $font-color-light;
		}
	}
	.default-row{
		margin-top: 16rpx;
		.tit{
			flex: 1;
		}
		switch{
			transform: translateX(16rpx) scale(.9);
		}
	}
	.add-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 690rpx;
		height: 80rpx;
		margin: 60rpx auto;
		font-size: $font-lg;
		color: #fff;
		background-color: $base-color;
		border-radius: 10rpx;
		box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
	}
</style>

